package component.change
{
	
	import baseInterface.change.IbaseState;
	
	import container.ADmultSkinContain;
	
	import skin.BaseSkin;
	
	public class ADmultStateChange extends ADmultSkinContain implements IbaseState
	{
		private var stateChangeFunc:Vector.<Function>=new Vector.<Function>;
		private var _state:int;
		/**
		 * 
		 * 
		 */
		public function ADmultStateChange()
		{
			stateChangeFunc.fixed=true;
			setStartState();
		}
		/**
		 *初始状态 
		 * 
		 */		
		public function setStartState():void
		{
			state=0;
			stateChangeFunc.unshift(defaultStateFunc);
		}
		/**
		 * 设置从 srcState到targState 的逻辑 函数 
		 * 
		 * @param srcState
		 * @param targState
		 * @param fun(src:int,des:int):boolean（return boolean）
		 * @see defaultStateFunc
		 * 
		 */		
		protected function setLogicFunc(srcState:int,targState:int,fun:Function):void
		{
			if(srcState<skinLen&&targState<skinLen)
			stateChangeFunc[srcState][targState]=fun;
		}
		/**
		 *改变状态方法 
		 * @param value
		 * 
		 */		
		public function set state(value:int):void
		{
			if(_state==value)return;
			if(value<skinLen)
			{
				stateChangeFunc[value]||=defaultStateFunc;
				stateChangeFunc[value](skinContainerVec,value);
				_state=value;
			}
		}
		/**
		 *得到状态方法 
		 * @return 
		 * 
		 */		
		public function get state():int
		{
			return _state;
		}
		/**
		 *默认 change changestate 
		 *  
		 * @return 
		 */		
		protected function defaultStateFunc(skins:*,index:int):void{return }
		
		public function defineState(index:int, stateFunc:Function):void
		{
			if(index>=stateCout)
				stateChangeFunc.length=index+1
			stateChangeFunc[index]=stateFunc;
		}
		
		public function get stateCout():int
		{
			// TODO Auto Generated method stub
			return stateChangeFunc.length;
		}
		public	function getStateFuncIndex(stateFunc:Function):int
		{
			return stateChangeFunc.indexOf(stateFunc);
		}
	}
}